import BasicCesium from '@/utils/cesium'
import Constant from '@/utils/constant'
import HawkEyeMap from '@/utils/hawkEyeMap'

export default {
  data() {
    return {}
  },
  methods: {
    basicMap(dom, option = null) {
      return new BasicCesium(dom, option)
    },
    addLayer(key) {
      let viewer = this.basicCesium.viewer
      if (viewer.imageryLayers._layers.length > 1) {
        viewer.imageryLayers.remove(viewer.imageryLayers.get(0));
      }
      viewer.imageryLayers.addImageryProvider(Constant.BASELAYER[key]())
    },
    terrainProvide(key) {
      let viewer = this.basicCesium.viewer
      switch (key) {
        case 'world':
          this.isTerrain(viewer)
          viewer.terrainProvider = Cesium.createWorldTerrain({
            requestWaterMask: true, // 请求水体效果所需要的海岸线数据
            requestVertexNormals: true, // 请求地形照明数据
          })
          break
        case 'ellipsoid':
          // viewer.scene.globe.depthTestAgainstTerrain = false
          viewer.terrainProvider = new Cesium.EllipsoidTerrainProvider({})
          break
        case 'asset':
          this.isTerrain(viewer)
          viewer.terrainProvider = new Cesium.CesiumTerrainProvider({
            url: Cesium.IonResource.fromAssetId(3956),
            requestWaterMask: true, // 请求水体效果所需要的海岸线数据
            requestVertexNormals: true, // 请求地形照明数据
          })
          break
      }
    },
    isTerrain(viewer) {
      let depth = viewer.scene.globe.depthTestAgainstTerrain
      if (!depth) {
        viewer.scene.globe.depthTestAgainstTerrain = true
      }
    },
    handleArrow(key) {
       switch (key) {
         case 'straight':
           this.arrow.draw('straightArrow', '#FF002A')
           break
         case 'attack':
           this.arrow.draw('attackArrow', '#0055FF')
           break
         case 'pincer':
           this.arrow.draw('pincerArrow', '#00FF55')
           break
         case 'clear':
           this.arrow.clearAll()
           break
       }
    },
    handleModelType(key) {
       switch (key) {
         case 'entity':
           this.modelType.initEntity()
           break
         case 'primitive':
           this.modelType.initPrimitive()
           break
         case 'clear':
           this.modelType.clearAll()
           break
       }
    },

    openEyemap() {
      let main = document.querySelector('#cesiumMap')
      let eyeDom = document.createElement('div')
      eyeDom.id = 'hawkEyeMap'
      main.appendChild(eyeDom)
      this.basicCesium = this.basicMap('cesium', {})
      let viewer = this.basicCesium.viewer
      //鹰眼
      this.$nextTick(() => {
        let hawkEyeMap = new HawkEyeMap(viewer)
        hawkEyeMap._init()
      })
    }
  }
}